package com.gec.system.controller;

import com.gec.system.common.Result;
import com.gec.system.config.WebSocket;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Api("聊天控制器")
@SuppressWarnings("rawtypes")
@CrossOrigin
@RestController
@RequestMapping("/system/imChat")
public class ChatController {
//    @Resource
//    private WebSocket webSocket;
//
////    建立连接
//
//    @ApiOperation("前端请求一个websocket")
//    @GetMapping("/onOpen")
//    public Result onOpen(HttpServletRequest req){
//
//    }



    @ApiOperation("获取聊天历史")
    @GetMapping("/findChat")
    public Result findChat(HttpServletRequest req){
//        获取接收方----->发送方的数据
        ArrayList toFromList = (ArrayList) req.getAttribute("to_from");
//        获取发送方----->接收方的数据
        ArrayList fromToList = (ArrayList)req.getAttribute("from_to");
        List historyChatUsersList = (List) req.getAttribute("historyChatUsers");
        System.out.println("获取的toFromList是："+toFromList);
        System.out.println("获取的fromToList是："+fromToList);
        System.out.println("获取的historyChatUsersList是："+historyChatUsersList);
        HashMap<String, Object> hashMap = new HashMap<>();
        if (toFromList==null||fromToList==null){
//            未进入聊天界面
            hashMap.put("chatList",historyChatUsersList);
        }else {
//            进入了聊天界面
            hashMap.put("to",toFromList);
            hashMap.put("from", fromToList);
        }
        return Result.ok(hashMap);
    }
}
